<?
$PageTitle=$msg["Page_DeleteNews"];

include "div_menu.php";

if (!check_admin_access())
  {return;}

if (!$_POST) 
{
  make_form($val);
} 
else 
{
  if (delete_news($val)) 
  {
    print_continue($msg["NewsDeleted"], "news");
  }
  else
  {
    echo '<a href="news">', $msg["Continue"], '</a><br><br>';
  }
};


//-----------------------------------------------------------------------------

function make_form($id) 
{
  global $msg;

  $news = db_read_news_by_id($id);

  if (!$news) 
  {
    echo '<br>';
    echo $msg["NewsNotFound"], '&nbsp;(id = ', $id, ')<br>';
    echo '<a href="news">', $msg["Continue"], '</a><br><br>';
    return;
  }

?>

<!-- Delete news form -->
<div class="form_area">
<div class="form_div">
<form action="newsdelete?id=<?=$id;?>" method="post">

  <fieldset class="fields1">

  <dl>
    <?=print_news($news);?>
  </dl>

  <dl class="button_div">
    <button type="submit" name="delete"><?=$msg["Delete"];?></button>
    &nbsp;
    <button type="button" name="cancel" onClick="history.go(-1)"><?=$msg["Cancel"];?></button>
  </dl>
  </fieldset>

</form>
</div>
</div>

<?php
};


//-----------------------------------------------------------------------------

function delete_news($id) 
{
  global $msg;

  $n = 0;

  try 
  {
    db_call();
    db_delete_news($id);
  } 
  catch (Exception $e) 
  {
    $errors[$n++] = $e->getMessage();
  }

  if ($n <> 0) 
  {
    print_errors($errors);
    return False;
  }

  return True;
};

?>
